package com.hksj.slm.controller;

import com.hksj.cbm.vo.RuleSceneVO;
import com.hksj.common.core.model.Rest;
import com.hksj.slm.dto.CockpitStatisticAnalysisDTO;
import com.hksj.slm.dto.DurationStatisticByBuildingIdDTO;
import com.hksj.slm.dto.DurationStatisticByFloorIdDTO;
import com.hksj.slm.dto.DurationStatisticByRoomIdDTO;
import com.hksj.slm.service.StatisticAnalysisService;
import com.hksj.slm.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @author fjt
 * @data 2024/8/22 10:21
 * @describe 智能照明统计分析
 */
@Api(tags = "智能照明-统计分析")
@RestController
@RequestMapping("/api/slm/statistic")
public class StatisticAnalysisController {


    @Autowired
    private StatisticAnalysisService statisticAnalysisService;



    @PostMapping("/overView")
    @ApiOperation(value = "设备概览", notes = "设备概览",response = SmartLightingDeviceOverviewVO.class)
    public Rest<SmartLightingDeviceOverviewVO> deviceOverView(@RequestBody CockpitStatisticAnalysisDTO dto){
        return Rest.ok(statisticAnalysisService.deviceOverView(dto));
    }


    @PostMapping("/durationRanking")
    @ApiOperation(value = "连续照明时长排名(前5)", notes = "连续照明时长排名(前5)",response = LightingDurationTopFiveVO.class)
    public Rest<List<LightingDurationTopFiveVO>>  LightingDurationRanking(@RequestBody CockpitStatisticAnalysisDTO dto){
        return Rest.ok(statisticAnalysisService.lightingDurationRanking(dto));
    }


    @GetMapping("/queryScheduledTasks/{ruleType}")
    @ApiOperation(value = "定时控制策略查询", notes = "定时控制策略查询，ruleType为规则策略类型(字典表中定义)",response = RuleSceneVO.class)
    public Rest<List<RuleSceneVO>> queryScheduledTasks(@PathVariable("ruleType") String ruleType){
        return Rest.ok(statisticAnalysisService.queryScheduledTasks(ruleType));
    }


    @PostMapping("/durationDetail")
    @ApiOperation(value = "统计指定房间中各回路的照明时长", notes = "统计指定房间中各回路的照明时长",response = LightingDurationGroupLoopVO.class)
    public Rest<LightingDurationGroupLoopVO> queryLightingDurationDetail(@RequestBody @Valid DurationStatisticByRoomIdDTO dto){
        return Rest.ok(statisticAnalysisService.queryLightingDurationDetail(dto));
    }


    @PostMapping("/exportList")
    @ApiOperation(value = "导出指定房间中各回路的照明时长", notes = "导出指定房间中各回路的照明时长")
    public void exportList(HttpServletResponse response, @RequestBody @Valid DurationStatisticByRoomIdDTO dto){
        statisticAnalysisService.exportList(response, dto);
    }


    @PostMapping("/durationGroupRoom")
    @ApiOperation(value = "按房间统计指定楼层或科室的累计照明时长", notes = "按房间统计指定楼层或科室的累计照明时长",response = LightingDurationGroupRoomVO.class)
    public Rest<List<LightingDurationGroupRoomVO>> queryLightingDurationGroupRoom(@RequestBody @Valid DurationStatisticByFloorIdDTO dto){
        return Rest.ok(statisticAnalysisService.queryLightingDurationGroupRoom(dto));
    }


    @PostMapping("/durationGroupFloor")
    @ApiOperation(value = "按楼层或科室统计指定楼栋的累计照明时长", notes = "按楼层或科室统计指定楼栋的累计照明时长",response = LightingDurationGroupFloorVO.class)
    public Rest<List<LightingDurationGroupFloorVO>> queryLightingDurationGroupFloor(@RequestBody @Valid DurationStatisticByBuildingIdDTO dto){
        return Rest.ok(statisticAnalysisService.queryLightingDurationGroupFloor(dto));
    }




}
